/*
 * Project Name spring-boot-tools
 * File Name SessionConfiguration
 * Package Name com.huxiaosu.tools.common.auth.confingure
 * Create Time 2024/7/26
 * Create by name：liujie
 */
package com.huxiaosu.tools.common.auth.confingure;

import com.huxiaosu.tools.common.auth.service.AuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Description
 *
 * @author liujie
 * @date 2024/7/26 17:27
 */
public class SessionConfiguration implements WebMvcConfigurer {
    @Bean
    public AuthInterceptor sessionInterceptor() {
        return new AuthInterceptor();
    }
    @Bean
    public IgnoreProperties ignoreProperties() {
        return new IgnoreProperties();
    }


    /**
     * 设置允许跨域请求
     * @param registry
     * @return void
     * @author liujie
     * @date 2021/7/15 21:29
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(true)
                .exposedHeaders(HttpHeaders.SET_COOKIE)
                .maxAge(3600L);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionInterceptor())
                .order(1)
                //.excludePathPatterns("/swagger-resources/**")
                //.excludePathPatterns("/v3/api-docs")
                //.excludePathPatterns("/v3/api-docs/**")
                //.excludePathPatterns("/favicon.ico")
                .addPathPatterns("/**");

    }
}